<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('hijriah'))
{
	function hijriah($tanggal){
		$theDate = explode(",",date("w,d,n,Y",strtotime($tanggal)));
		$wday = $theDate[0];
		$hr = $theDate[1];
		$theMonth = $theDate[2];
		$theYear = $theDate[3];

		if (($theYear > 1582) || (($theYear == 1582) && ($theMonth > 10)) || (($theYear == 1582) && ($theMonth == 10) && ($hr > 14))) {
			$zjd = (int)((1461 * ($theYear + 4800 + (int)(($theMonth - 14) / 12))) / 4) + (int)((367 * ($theMonth - 2 - 12 * ((int)(($theMonth - 14) / 12)))) / 12) - (int)((3 * (int)((($theYear + 4900 + (int)(($theMonth - 14) / 12)) / 100))) / 4) + $hr - 32075;
		} else {
			$zjd = 367 * $theYear - (int)((7 * ($theYear + 5001 + (int)(($theMonth - 9) / 7))) / 4) + (int)((275 * $theMonth) / 9) + $hr + 1729777;
		}

		$zl				= $zjd - 1948440 + 10632;
		$zn            	= (int)(($zl-1)/10631);
		$zl            	= $zl - 10631 * $zn + 354;
		$zj            	= ((int)((10985 - $zl)/5316))*((int)((50 * $zl)/17719))+((int)($zl/5670))*((int)((43 * $zl)/15238));
		$zl            	= $zl-((int)((30 - $zj)/15))*((int)((17719 * $zj)/50))-((int)($zj/16))*((int)((15238 * $zj)/43))+29;
		$theMonth    	= (int)((24 * $zl)/709);
		$hijriDay    	= $zl-(int)((709 * $theMonth)/24);
		$hijriYear    	= 30 * $zn + $zj - 30;

		if ($theMonth==1){ $hijriMonthName = "Muharrom";}
		if ($theMonth==2){ $hijriMonthName = "Shofar";}
		if ($theMonth==3){ $hijriMonthName = "Robiul Awal";}
		if ($theMonth==4){ $hijriMonthName = "Robiul Akhir";}
		if ($theMonth==5){ $hijriMonthName = "Jumadil Awal";}
		if ($theMonth==6){ $hijriMonthName = "Jumadil Akhir";}
		if ($theMonth==7){ $hijriMonthName = "Rojab";}
		if ($theMonth==8){ $hijriMonthName = "Sya'ban";}
		if ($theMonth==9){ $hijriMonthName = "Romadlon";}
		if ($theMonth==10){ $hijriMonthName = "Syawal";}
		if ($theMonth==11){ $hijriMonthName = "Dzulqo'dah";}
		if ($theMonth==12){ $hijriMonthName = "Dzulhijjah";}

		if ($wday==0) { $hijriDayString = "Ahad"; }
		if ($wday==1) { $hijriDayString = "Senin"; }
		if ($wday==2) { $hijriDayString = "Selasa"; }
		if ($wday==3) { $hijriDayString = "Rabu"; }
		if ($wday==4) { $hijriDayString = "Kamis"; }
		if ($wday==5) { $hijriDayString = "Jum'at"; }
		if ($wday==6) { $hijriDayString = "Sabtu"; }

		return $hijriDayString .', ' . $hijriDay . ' ' . $hijriMonthName . ' ' . $hijriYear . ' H';
	}
	
	function hijriahTanpaHari($tanggal){
		$theDate = explode(",",date("w,d,n,Y",strtotime($tanggal)));
		$wday = $theDate[0];
		$hr = $theDate[1];
		$theMonth = $theDate[2];
		$theYear = $theDate[3];

		if (($theYear > 1582) || (($theYear == 1582) && ($theMonth > 10)) || (($theYear == 1582) && ($theMonth == 10) && ($hr > 14))) {
			$zjd = (int)((1461 * ($theYear + 4800 + (int)(($theMonth - 14) / 12))) / 4) + (int)((367 * ($theMonth - 2 - 12 * ((int)(($theMonth - 14) / 12)))) / 12) - (int)((3 * (int)((($theYear + 4900 + (int)(($theMonth - 14) / 12)) / 100))) / 4) + $hr - 32075;
		} else {
			$zjd = 367 * $theYear - (int)((7 * ($theYear + 5001 + (int)(($theMonth - 9) / 7))) / 4) + (int)((275 * $theMonth) / 9) + $hr + 1729777;
		}

		$zl				= $zjd - 1948440 + 10632;
		$zn            	= (int)(($zl-1)/10631);
		$zl            	= $zl - 10631 * $zn + 354;
		$zj            	= ((int)((10985 - $zl)/5316))*((int)((50 * $zl)/17719))+((int)($zl/5670))*((int)((43 * $zl)/15238));
		$zl            	= $zl-((int)((30 - $zj)/15))*((int)((17719 * $zj)/50))-((int)($zj/16))*((int)((15238 * $zj)/43))+29;
		$theMonth    	= (int)((24 * $zl)/709);
		$hijriDay    	= $zl-(int)((709 * $theMonth)/24);
		$hijriYear    	= 30 * $zn + $zj - 30;

		if ($theMonth==1){ $hijriMonthName = "Muharrom";}
		if ($theMonth==2){ $hijriMonthName = "Shofar";}
		if ($theMonth==3){ $hijriMonthName = "Robiul Awal";}
		if ($theMonth==4){ $hijriMonthName = "Robiul Akhir";}
		if ($theMonth==5){ $hijriMonthName = "Jumadil Awal";}
		if ($theMonth==6){ $hijriMonthName = "Jumadil Akhir";}
		if ($theMonth==7){ $hijriMonthName = "Rojab";}
		if ($theMonth==8){ $hijriMonthName = "Sya'ban";}
		if ($theMonth==9){ $hijriMonthName = "Romadlon";}
		if ($theMonth==10){ $hijriMonthName = "Syawal";}
		if ($theMonth==11){ $hijriMonthName = "Dzulqo'dah";}
		if ($theMonth==12){ $hijriMonthName = "Dzulhijjah";}

		return $hijriDay . ' ' . $hijriMonthName . ' ' . $hijriYear . ' H';
	}
	
	function hijriahSimple($tanggal){
		$theDate = explode(",",date("w,d,n,Y",strtotime($tanggal)));
		$wday = $theDate[0];
		$hr = $theDate[1];
		$theMonth = $theDate[2];
		$theYear = $theDate[3];

		if (($theYear > 1582) || (($theYear == 1582) && ($theMonth > 10)) || (($theYear == 1582) && ($theMonth == 10) && ($hr > 14))) {
			$zjd = (int)((1461 * ($theYear + 4800 + (int)(($theMonth - 14) / 12))) / 4) + (int)((367 * ($theMonth - 2 - 12 * ((int)(($theMonth - 14) / 12)))) / 12) - (int)((3 * (int)((($theYear + 4900 + (int)(($theMonth - 14) / 12)) / 100))) / 4) + $hr - 32075;
		} else {
			$zjd = 367 * $theYear - (int)((7 * ($theYear + 5001 + (int)(($theMonth - 9) / 7))) / 4) + (int)((275 * $theMonth) / 9) + $hr + 1729777;
		}

		$zl				= $zjd - 1948440 + 10632;
		$zn            	= (int)(($zl-1)/10631);
		$zl            	= $zl - 10631 * $zn + 354;
		$zj            	= ((int)((10985 - $zl)/5316))*((int)((50 * $zl)/17719))+((int)($zl/5670))*((int)((43 * $zl)/15238));
		$zl            	= $zl-((int)((30 - $zj)/15))*((int)((17719 * $zj)/50))-((int)($zj/16))*((int)((15238 * $zj)/43))+29;
		$theMonth    	= (int)((24 * $zl)/709);
		$hijriDay    	= $zl-(int)((709 * $theMonth)/24);
		$hijriYear    	= 30 * $zn + $zj - 30;

		if ($theMonth==1){ $hijriMonthNumber = "01";}
		if ($theMonth==2){ $hijriMonthNumber = "02";}
		if ($theMonth==3){ $hijriMonthNumber = "03";}
		if ($theMonth==4){ $hijriMonthNumber = "04";}
		if ($theMonth==5){ $hijriMonthNumber = "05";}
		if ($theMonth==6){ $hijriMonthNumber = "06";}
		if ($theMonth==7){ $hijriMonthNumber = "07";}
		if ($theMonth==8){ $hijriMonthNumber = "08";}
		if ($theMonth==9){ $hijriMonthNumber = "09";}
		if ($theMonth==10){ $hijriMonthNumber = "10";}
		if ($theMonth==11){ $hijriMonthNumber = "11";}
		if ($theMonth==12){ $hijriMonthNumber = "12";}
		
		if ($hijriDay==1){ $hijriDayNumber = "01";}
		if ($hijriDay==2){ $hijriDayNumber = "02";}
		if ($hijriDay==3){ $hijriDayNumber = "03";}
		if ($hijriDay==4){ $hijriDayNumber = "04";}
		if ($hijriDay==5){ $hijriDayNumber = "05";}
		if ($hijriDay==6){ $hijriDayNumber = "06";}
		if ($hijriDay==7){ $hijriDayNumber = "07";}
		if ($hijriDay==8){ $hijriDayNumber = "08";}
		if ($hijriDay==9){ $hijriDayNumber = "09";}
		if ($hijriDay==10){ $hijriDayNumber = "10";}
		if ($hijriDay==11){ $hijriDayNumber = "11";}
		if ($hijriDay==12){ $hijriDayNumber = "12";}
		if ($hijriDay==13){ $hijriDayNumber = "13";}
		if ($hijriDay==14){ $hijriDayNumber = "14";}
		if ($hijriDay==15){ $hijriDayNumber = "15";}
		if ($hijriDay==16){ $hijriDayNumber = "16";}
		if ($hijriDay==17){ $hijriDayNumber = "17";}
		if ($hijriDay==18){ $hijriDayNumber = "18";}
		if ($hijriDay==19){ $hijriDayNumber = "19";}
		if ($hijriDay==20){ $hijriDayNumber = "20";}
		if ($hijriDay==21){ $hijriDayNumber = "21";}
		if ($hijriDay==22){ $hijriDayNumber = "22";}
		if ($hijriDay==23){ $hijriDayNumber = "23";}
		if ($hijriDay==24){ $hijriDayNumber = "24";}
		if ($hijriDay==25){ $hijriDayNumber = "25";}
		if ($hijriDay==26){ $hijriDayNumber = "26";}
		if ($hijriDay==27){ $hijriDayNumber = "27";}
		if ($hijriDay==28){ $hijriDayNumber = "28";}
		if ($hijriDay==29){ $hijriDayNumber = "29";}
		if ($hijriDay==30){ $hijriDayNumber = "30";}

		return $hijriDayNumber . '/' . $hijriMonthNumber . '/' . $hijriYear;
	}
	
	function hijriahSimpleStrip($theDate){
		$theDate = explode(",",date("w,d,n,Y",strtotime($tanggal)));
		$wday = $theDate[0];
		$hr = $theDate[1];
		$theMonth = $theDate[2];
		$theYear = $theDate[3];

		if (($theYear > 1582) || (($theYear == 1582) && ($theMonth > 10)) || (($theYear == 1582) && ($theMonth == 10) && ($hr > 14))) {
			$zjd = (int)((1461 * ($theYear + 4800 + (int)(($theMonth - 14) / 12))) / 4) + (int)((367 * ($theMonth - 2 - 12 * ((int)(($theMonth - 14) / 12)))) / 12) - (int)((3 * (int)((($theYear + 4900 + (int)(($theMonth - 14) / 12)) / 100))) / 4) + $hr - 32075;
		} else {
			$zjd = 367 * $theYear - (int)((7 * ($theYear + 5001 + (int)(($theMonth - 9) / 7))) / 4) + (int)((275 * $theMonth) / 9) + $hr + 1729777;
		}

		$zl				= $zjd - 1948440 + 10632;
		$zn            	= (int)(($zl-1)/10631);
		$zl            	= $zl - 10631 * $zn + 354;
		$zj            	= ((int)((10985 - $zl)/5316))*((int)((50 * $zl)/17719))+((int)($zl/5670))*((int)((43 * $zl)/15238));
		$zl            	= $zl-((int)((30 - $zj)/15))*((int)((17719 * $zj)/50))-((int)($zj/16))*((int)((15238 * $zj)/43))+29;
		$theMonth    	= (int)((24 * $zl)/709);
		$hijriDay    	= $zl-(int)((709 * $theMonth)/24);
		$hijriYear    	= 30 * $zn + $zj - 30;

		if ($theMonth==1){ $hijriMonthNumber = "01";}
		if ($theMonth==2){ $hijriMonthNumber = "02";}
		if ($theMonth==3){ $hijriMonthNumber = "03";}
		if ($theMonth==4){ $hijriMonthNumber = "04";}
		if ($theMonth==5){ $hijriMonthNumber = "05";}
		if ($theMonth==6){ $hijriMonthNumber = "06";}
		if ($theMonth==7){ $hijriMonthNumber = "07";}
		if ($theMonth==8){ $hijriMonthNumber = "08";}
		if ($theMonth==9){ $hijriMonthNumber = "09";}
		if ($theMonth==10){ $hijriMonthNumber = "10";}
		if ($theMonth==11){ $hijriMonthNumber = "11";}
		if ($theMonth==12){ $hijriMonthNumber = "12";}
		
		if ($hijriDay==1){ $hijriDayNumber = "01";}
		if ($hijriDay==2){ $hijriDayNumber = "02";}
		if ($hijriDay==3){ $hijriDayNumber = "03";}
		if ($hijriDay==4){ $hijriDayNumber = "04";}
		if ($hijriDay==5){ $hijriDayNumber = "05";}
		if ($hijriDay==6){ $hijriDayNumber = "06";}
		if ($hijriDay==7){ $hijriDayNumber = "07";}
		if ($hijriDay==8){ $hijriDayNumber = "08";}
		if ($hijriDay==9){ $hijriDayNumber = "09";}
		if ($hijriDay==10){ $hijriDayNumber = "10";}
		if ($hijriDay==11){ $hijriDayNumber = "11";}
		if ($hijriDay==12){ $hijriDayNumber = "12";}
		if ($hijriDay==13){ $hijriDayNumber = "13";}
		if ($hijriDay==14){ $hijriDayNumber = "14";}
		if ($hijriDay==15){ $hijriDayNumber = "15";}
		if ($hijriDay==16){ $hijriDayNumber = "16";}
		if ($hijriDay==17){ $hijriDayNumber = "17";}
		if ($hijriDay==18){ $hijriDayNumber = "18";}
		if ($hijriDay==19){ $hijriDayNumber = "19";}
		if ($hijriDay==20){ $hijriDayNumber = "20";}
		if ($hijriDay==21){ $hijriDayNumber = "21";}
		if ($hijriDay==22){ $hijriDayNumber = "22";}
		if ($hijriDay==23){ $hijriDayNumber = "23";}
		if ($hijriDay==24){ $hijriDayNumber = "24";}
		if ($hijriDay==25){ $hijriDayNumber = "25";}
		if ($hijriDay==26){ $hijriDayNumber = "26";}
		if ($hijriDay==27){ $hijriDayNumber = "27";}
		if ($hijriDay==28){ $hijriDayNumber = "28";}
		if ($hijriDay==29){ $hijriDayNumber = "29";}
		if ($hijriDay==30){ $hijriDayNumber = "30";}

		return $hijriDayNumber . '-' . $hijriMonthNumber . '-' . $hijriYear;
	}
}